import { Toast } from "vant";
import {
    addDynamic
} from "@/request/write-dynamic-request";


export const useAddDynamic = async (user,dynamic) => {
    try{
        if(dynamic.dynamic_content.length <= 0){
            return Toast("内容不能为空")
        }
        dynamic.dynamic_user_avatar = user.userInfo.avatar;
        dynamic.dynamic_creator_name = user.userInfo.nick_name;
        dynamic.dynamic_creator_id = user.userInfo._id;
        const result = await addDynamic(dynamic);
        if(result.code === 201 && result.message === "success"){
             Toast("发布成功")
             location.reload();
        }else{
            Toast(result.message)
        }
    }catch(error){
        Toast(error.message)
    }
}